﻿Option Strict On
Option Explicit On

Imports CObject
Imports ConnectionServer
Imports System.Data.SqlClient
Namespace CMT

    Public Class CMTFeedback
        Inherits CObject.CObject

        Public Sub New()
            MyBase.New()
        End Sub

        Public Sub New(ByVal piFeedbackID As Integer)
            MyBase.New(piFeedbackID)
        End Sub

        Public Overrides Function Clone() As CObject.CObject
            Return New CMTFeedback()
        End Function

        Public Overrides ReadOnly Property Key As String
            Get
                Return "FeedbackID"
            End Get
        End Property
        Public Property FeedBackData As String
            Get
                Return CastToString(GetProperty("FeedBackData"))
            End Get
            Set(ByVal value As String)
                SetProperty("FeedBackData", value)
            End Set
        End Property


        Protected Overrides Function ProcedureSigniture(ByVal peCommandType As CObject.CommandType) As String
            Select Case peCommandType
                Case CommandType.SQLSelect
                    Return "SELECT * FROM CMT_Feedbacks "
                Case CommandType.SQLInsert
                    Return "EXEC CMT_FeedbackAdd  { FeedBackData} "
                Case Else
                    Throw New SystemException("Invalid Command Type")
            End Select
        End Function
        Public Overrides Sub Save()
            Dim loTran As New CTransaction()

            loTran.HasOutPut = True
            AddHandler loTran.TransactionOutput, AddressOf OuputHandler
            loTran.AddObject(Me)
            loTran.Save()


        End Sub
        Private Sub OuputHandler(ByVal value As Object)
            ' DocumentID = CInt(value)
        End Sub


        Public Overrides ReadOnly Property SourceDataBase As ConnectionServer.Connection.SourceDataBase
            Get
                Return Connection.SourceDataBase.CMT
            End Get
        End Property

#Region "Properties"

        Public ReadOnly Property FeedbackID As Integer
            Get
                Return CastToInteger(GetProperty("FeedbackID"))
            End Get
        End Property

        Public Property AttendeeID As Integer
            Get
                Return CastToInteger(GetProperty("AttendeeID"))
            End Get
            Set(ByVal value As Integer)
                SetProperty("AttendeeID", value)
            End Set
        End Property

        Public ReadOnly Property MeetingAttendeeObj As MeetingAttendee
            Get
                Dim loObj As MeetingAttendee = New MeetingAttendee(AttendeeID)
                If loObj.EventAttendeeID <> 0 Then
                    Return loObj
                Else
                    'no data
                    Return Nothing
                End If
            End Get
        End Property

        Public Property Country As String
            Get
                Return CastToString(GetProperty("Country"))
            End Get
            Set(ByVal value As String)
                SetProperty("Country", value)
            End Set
        End Property

        Public Property SubServiceLine As String
            Get
                Return CastToString(GetProperty("SubServiceLine"))
            End Get
            Set(ByVal value As String)
                SetProperty("SubServiceLine", value)
            End Set
        End Property

        Public Property PrimaryObjectivesAndChallenges As String
            Get
                Return CastToString(GetProperty("PrimObjectivesChallenges"))
            End Get
            Set(ByVal value As String)
                SetProperty("PrimObjectivesChallenges", value)
            End Set
        End Property

        Public Property PrimaryTaxIssues As String
            Get
                Return CastToString(GetProperty("PrimTaxIssues"))
            End Get
            Set(ByVal value As String)
                SetProperty("PrimTaxIssues", value)
            End Set
        End Property

        Public Property OpportunityOrProjectIdentified As Boolean
            Get
                Return CastToBoolean(GetProperty("OpportunityProjectIdentified"))
            End Get
            Set(ByVal value As Boolean)
                SetProperty("OpportunityProjectIdentified", value)
            End Set
        End Property

        Public Property DescriptionOfOpportunityOrProject As String
            Get
                Return CastToString(GetProperty("DescrOpportunityProject"))
            End Get
            Set(ByVal value As String)
                SetProperty("DescrOpportunityProject", value)
            End Set
        End Property

        Public Property Stage As String
            Get
                Return CastToString(GetProperty("Stage"))
            End Get
            Set(ByVal value As String)
                SetProperty("Stage", value)
            End Set
        End Property

        Public Property PotentialTaxFees As Double
            Get
                Return CastToDouble(GetProperty("PotentialTaxFees"))
            End Get
            Set(ByVal value As Double)
                SetProperty("PotentialTaxFees", value)
            End Set
        End Property

        Public Property ProbabilityOfWin As String
            Get
                Return CastToString(GetProperty("ProbabilityOfWin"))
            End Get
            Set(ByVal value As String)
                SetProperty("ProbabilityOfWin", value)
            End Set
        End Property

        Public Property ExpectedTimeFrame As Date
            Get
                Return CastToDate(GetProperty("ExpectedTimeFrame"))
            End Get
            Set(ByVal value As Date)
                SetProperty("ExpectedTimeFrame", value)
            End Set
        End Property

        Public Property NextSteps As String
            Get
                Return CastToString(GetProperty("NextSteps"))
            End Get
            Set(ByVal value As String)
                SetProperty("NextSteps", value)
            End Set
        End Property

        Public Property ResponsibilityForMovingForward As String
            Get
                Return CastToString(GetProperty("Responsibility"))
            End Get
            Set(ByVal value As String)
                SetProperty("Responsibility", value)
            End Set
        End Property

        Public Property AdditionalInformation As String
            Get
                Return CastToString(GetProperty("AdditionalInformation"))
            End Get
            Set(ByVal value As String)
                SetProperty("AdditionalInformation", value)
            End Set
        End Property

#End Region

#Region "Methods"

        ''' <summary>
        ''' Method: AddFeedBack
        ''' </summary>
        ''' <param name="eventName"></param>
        ''' <param name="eventdescription"></param>
        ''' <param name="country"></param>
        ''' <param name="startdate"></param>
        ''' <remarks>
        ''' Inserts a line keeping track of any changes made in RM
        ''' </remarks>
        Public Function AddFeedBAck(ByVal xml As String) As String
            Dim message As String
            Using loConn As Connection = New Connection(Connection.SourceDataBase.CMT)

                Dim loCommand As SqlCommand = New SqlCommand
                'set the connection
                loCommand.Connection = loConn.Connection

                ' Set the parameters
                loCommand.Parameters.Add("@pXmlString", SqlDbType.VarChar, 8000)
                loCommand.Parameters("@pXmlString").Value = xml

                ' Add Output Parameter
                Dim loParamInstance As SqlParameter = New SqlParameter("@Output", SqlDbType.NVarChar, 100)
                loParamInstance.Direction = ParameterDirection.Output
                loCommand.Parameters.Add(loParamInstance)


                loCommand.CommandType = Data.CommandType.StoredProcedure
                loCommand.CommandText = "CMT_FeedbackAdd"

                'Execute the Query
                loCommand.ExecuteNonQuery()
                loConn.Connection.Close()

                message = loCommand.Parameters("@Output").Value.ToString()
                Return message
            End Using
        End Function

        Public Function CheckFeedbackStatus(ByVal EventAttendeeId As Integer, ByRef OutPut As Integer) As DataTable
            Dim dtFeedbackDetails As DataTable = New DataTable()
            Using loConn As Connection = New Connection(Connection.SourceDataBase.CMT)

                Dim loCommand As SqlCommand = New SqlCommand
                'set the connection
                loCommand.Connection = loConn.Connection

                ' Set the parameters
                loCommand.Parameters.Add("@pCreatedEventAttendeeID", SqlDbType.Int)
                loCommand.Parameters("@pCreatedEventAttendeeID").Value = EventAttendeeId

                ' Add Output Parameter
                Dim loParamInstance As SqlParameter = New SqlParameter("@Output", SqlDbType.Int)
                loParamInstance.Direction = ParameterDirection.Output
                loCommand.Parameters.Add(loParamInstance)

                loCommand.CommandType = Data.CommandType.StoredProcedure
                loCommand.CommandText = "CMT_CheckFeedbackStatus"
         

                Dim loAdp As SqlDataAdapter = New SqlDataAdapter(loCommand)
                Dim loDs As DataSet = New DataSet
                loAdp.Fill(loDs)
                If (loDs.Tables.Count > 0) Then dtFeedbackDetails = loDs.Tables(0)
                OutPut = Convert.ToInt32(loCommand.Parameters("@Output").Value.ToString())
                Return dtFeedbackDetails
            End Using
        End Function
        ''' <summary>
        ''' Method to get the Event details.
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Function GetFeedBackFormDetails(ByVal EventAttendeeId As Integer) As DataSet

            Using loConn As Connection = New Connection(Connection.SourceDataBase.CMT)
                Dim loCommand As SqlCommand = New SqlCommand
                loCommand.CommandType = Data.CommandType.StoredProcedure
                loCommand.Connection = loConn.Connection
                loCommand.Parameters.Add("@pEventAttendeeId", SqlDbType.Int)
                loCommand.Parameters("@pEventAttendeeId").Value = EventAttendeeId
                loCommand.CommandText = "CMT_GetFeedbackCombos"
                Dim loAdp As SqlDataAdapter = New SqlDataAdapter(loCommand)
                Dim loDs As DataSet = New DataSet
                loAdp.Fill(loDs)
                Return loDs
            End Using
        End Function
        ''' <summary>
        ''' Method: GetEventDetails
        ''' </summary>
        ''' <param name="currentUserGUI"></param>
        ''' <remarks>
        ''' Inserts a line keeping track of any changes made in RM
        ''' </remarks>
        Public Function GetAllEventDetails(ByVal currentUserGUI As String) As DataTable
            Using loConn As Connection = New Connection(Connection.SourceDataBase.CMT)
                Dim lsSQL As String = "EXEC CMT_GetEventsDetails '" & currentUserGUI & "'"
                Dim loDT As DataTable
                loDT = loConn.GetDataTable(lsSQL)
                Return loDT
            End Using
        End Function


        ''' <summary>
        ''' Method: GetEventDetails
        ''' </summary>
        ''' <param name="EventId"></param>
        ''' <remarks>
        ''' Inserts a line keeping track of any changes made in RM
        ''' </remarks>
        Public Function GetMeetingDetails(ByVal EventId As String) As DataTable
            Using loConn As Connection = New Connection(Connection.SourceDataBase.CMT)

                Dim loCommand As SqlCommand = New SqlCommand
                loCommand.CommandType = Data.CommandType.StoredProcedure
                loCommand.Connection = loConn.Connection
                loCommand.Parameters.Add("@pEevntId", SqlDbType.Int)
                loCommand.Parameters("@pEevntId").Value = EventId

                loCommand.CommandText = "CMT_GetMeetingDetailsForEvent"
                Dim loAdp As SqlDataAdapter = New SqlDataAdapter(loCommand)
                Dim loDs As DataSet = New DataSet
                loAdp.Fill(loDs)
                Return loDs.Tables(0)
            End Using
        End Function


        Public Function GetFeedbackDetails(ByVal EventId As String, ByVal EventAttendeeId As String, ByVal FeedbackId As String) As DataTable
            Using loConn As Connection = New Connection(Connection.SourceDataBase.CMT)

                Dim loCommand As SqlCommand = New SqlCommand
                loCommand.CommandType = Data.CommandType.StoredProcedure
                loCommand.Connection = loConn.Connection
                loCommand.Parameters.Add("@pEventId", SqlDbType.Int)
                loCommand.Parameters("@pEventId").Value = EventId

                If (FeedbackId <> "0") Then
                    loCommand.Parameters.Add("@pFeedbackId", SqlDbType.Int)
                    loCommand.Parameters("@pFeedbackId").Value = FeedbackId

                End If
                If (EventAttendeeId <> "0") Then
                    loCommand.Parameters.Add("@pEventAttendeeId", SqlDbType.Int)
                    loCommand.Parameters("@pEventAttendeeId").Value = EventAttendeeId

                End If

                loCommand.CommandText = "CMT_GetFeedbackSubmittDetails"
                Dim loAdp As SqlDataAdapter = New SqlDataAdapter(loCommand)
                Dim loDs As DataSet = New DataSet
                loAdp.Fill(loDs)
                Return loDs.Tables(0)
            End Using
        End Function
#End Region

    End Class

    Public Class CMTSubServiceLine
        Inherits CObject.CObject

        Public Sub New()
            MyBase.New()
        End Sub

        Public Overrides Function Clone() As CObject.CObject
            Return New CMTSubServiceLine
        End Function

        Public Sub New(ByVal piSSLID As Integer)
            MyBase.New(piSSLID)
        End Sub

        Public Overrides ReadOnly Property Key As String
            Get
                Return "SubServiceLineId"
            End Get
        End Property

        Protected Overrides Function ProcedureSigniture(ByVal peCommandType As CObject.CommandType) As String
            Select Case peCommandType
                Case CommandType.SQLSelect
                    Return "SELECT SubServiceLineId as Value ,SSLName as Name FROM dbo.CMT_SubserviceLine WHERE isactive=1 "
                Case Else
                    Throw New SystemException("Invalid Command Type")
            End Select
        End Function

        Public Overrides ReadOnly Property SourceDataBase As ConnectionServer.Connection.SourceDataBase
            Get
                Return Connection.SourceDataBase.CMT
            End Get
        End Property

    End Class


    Public Class CMTStage
        Inherits CObject.CObject

        Public Sub New()
            MyBase.New()
        End Sub

        Public Overrides Function Clone() As CObject.CObject
            Return New CMTStage
        End Function

        Public Sub New(ByVal piStageId As Integer)
            MyBase.New(piStageId)
        End Sub

        Public Overrides ReadOnly Property Key As String
            Get
                Return "StageId"
            End Get
        End Property

        Protected Overrides Function ProcedureSigniture(ByVal peCommandType As CObject.CommandType) As String
            Select Case peCommandType
                Case CommandType.SQLSelect
                    Return "SELECT StageId as Value ,StageName as Name FROM  dbo.CMT_Stage WHERE IsActive=1 "
                Case Else
                    Throw New SystemException("Invalid Command Type")
            End Select
        End Function

        Public Overrides ReadOnly Property SourceDataBase As ConnectionServer.Connection.SourceDataBase
            Get
                Return Connection.SourceDataBase.CMT
            End Get
        End Property

    End Class


    Public Class CMTTimeFrame
        Inherits CObject.CObject

        Public Sub New()
            MyBase.New()
        End Sub

        Public Overrides Function Clone() As CObject.CObject
            Return New CMTTimeFrame
        End Function

        Public Sub New(ByVal piTimeFrameId As Integer)
            MyBase.New(piTimeFrameId)
        End Sub

        Public Overrides ReadOnly Property Key As String
            Get
                Return "TimeFrameId"
            End Get
        End Property

        Protected Overrides Function ProcedureSigniture(ByVal peCommandType As CObject.CommandType) As String
            Select Case peCommandType
                Case CommandType.SQLSelect
                    Return "SELECT TimeFrameId as Value ,TimeFrame as Name FROM  dbo.CMT_TimeFrame WHERE isactive=1"

                Case Else
                    Throw New SystemException("Invalid Command Type")
            End Select
        End Function

        Public Overrides ReadOnly Property SourceDataBase As ConnectionServer.Connection.SourceDataBase
            Get
                Return Connection.SourceDataBase.CMT
            End Get
        End Property

    End Class


    Public Class CMTProbabilityOfWin
        Inherits CObject.CObject

        Public Sub New()
            MyBase.New()
        End Sub

        Public Overrides Function Clone() As CObject.CObject
            Return New CMTProbabilityOfWin
        End Function

        Public Sub New(ByVal piWinId As Integer)
            MyBase.New(piWinId)
        End Sub

        Public Overrides ReadOnly Property Key As String
            Get
                Return "WinId"
            End Get
        End Property

        Protected Overrides Function ProcedureSigniture(ByVal peCommandType As CObject.CommandType) As String
            Select Case peCommandType
                Case CommandType.SQLSelect
                    Return "SELECT WinId as Value,WinName as Name FROM dbo.CMT_ProbabilityOfWin WHERE isactive=1"
                Case Else
                    Throw New SystemException("Invalid Command Type")
            End Select
        End Function

        Public Overrides ReadOnly Property SourceDataBase As ConnectionServer.Connection.SourceDataBase
            Get
                Return Connection.SourceDataBase.CMT
            End Get
        End Property

    End Class

    Public Class CMTCompany
        Inherits CObject.CObject

        Public Sub New()
            MyBase.New()
        End Sub

        Public Overrides Function Clone() As CObject.CObject
            Return New CMTCompany
        End Function

        Public Sub New(ByVal pCompanyId As Integer)
            MyBase.New(pCompanyId)
        End Sub

        Public Overrides ReadOnly Property Key As String
            Get
                Return "CompanyId"
            End Get
        End Property
        Public Property EventAttendeeID As String
            Get
                Return CastToString(GetProperty("EventAttendeeID"))
            End Get
            Set(ByVal value As String)
                SetProperty("EventAttendeeID", value)
            End Set
        End Property

        Protected Overrides Function ProcedureSigniture(ByVal peCommandType As CObject.CommandType) As String
            Select Case peCommandType
                Case CommandType.SQLSelect
                    Return "SELECT DISTINCT Office FROM CMT_EventAttendees WHERE EventAttendeeID  = " & EventAttendeeID & "  AND IsClient = 0 AND isactive=1"
                Case Else
                    Throw New SystemException("Invalid Command Type")
            End Select
        End Function


        Public Overrides ReadOnly Property SourceDataBase As ConnectionServer.Connection.SourceDataBase
            Get
                Return Connection.SourceDataBase.CMT
            End Get
        End Property

    End Class

    Public Class CMTCOuntry
        Inherits CObject.CObject

        Public Sub New()
            MyBase.New()
        End Sub

        Public Overrides Function Clone() As CObject.CObject
            Return New CMTCOuntry
        End Function

        Public Sub New(ByVal pCompanyId As Integer)
            MyBase.New(pCompanyId)
        End Sub

        Public Overrides ReadOnly Property Key As String
            Get
                Return "CountryId"
            End Get
        End Property
        Public Property EventAttendeeID As String
            Get
                Return CastToString(GetProperty("EventAttendeeID"))
            End Get
            Set(ByVal value As String)
                SetProperty("EventAttendeeID", value)
            End Set
        End Property
        Protected Overrides Function ProcedureSigniture(ByVal peCommandType As CObject.CommandType) As String
            Select Case peCommandType
                Case CommandType.SQLSelect
                    Return "SELECT  DISTINCT ccr.CountryRepresentingId as Value,ccr.Country as Name FROM CMT_CountryRepresent ccr	JOIN CMT_EventAttendees cea ON ccr.EventAttendeeId = cea.EventAttendeeID 	AND cea.EventAttendeeId =" & EventAttendeeID & " AND cea.IsClient = 0 AND cea.isactive=1"

                Case Else
                    Throw New SystemException("Invalid Command Type")
            End Select
        End Function

        Public Overrides ReadOnly Property SourceDataBase As ConnectionServer.Connection.SourceDataBase
            Get
                Return Connection.SourceDataBase.CMT
            End Get
        End Property
    End Class

End Namespace
